// To parse this JSON data, do
//
//     final trajectoryDetailModel = trajectoryDetailModelFromJson(jsonString);

import 'dart:convert';

TrajectoryDetailModel trajectoryDetailModelFromJson(String str) => TrajectoryDetailModel.fromJson(json.decode(str));

String trajectoryDetailModelToJson(TrajectoryDetailModel data) => json.encode(data.toJson());

class TrajectoryDetailModel {
  int id;
  String caption;
  var speed;
  var distance;
  var asl;
  int time;
  int finished;
  DateTime createAt;
  bool fav;
  List<List<Point>> points;
  List<Marker> markers;

  TrajectoryDetailModel({
    required this.id,
    required this.caption,
    required this.speed,
    required this.distance,
    required this.asl,
    required this.time,
    required this.finished,
    required this.createAt,
    required this.fav,
    required this.points,
    required this.markers,
  });

  factory TrajectoryDetailModel.fromJson(Map<String, dynamic> json) => TrajectoryDetailModel(
    id: json["id"],
    caption: json["caption"],
    speed: json["speed"],
    distance: json["distance"],
    asl: json["asl"],
    time: json["time"],
    finished: json["finished"],
    createAt: DateTime.parse(json["createAt"]),
    fav: json["fav"],
    points: List<List<Point>>.from(json["points"].map((x) => List<Point>.from(x.map((x) => Point.fromJson(x))))),
    markers: List<Marker>.from(json["markers"].map((x) => Marker.fromJson(x))),
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "caption": caption,
    "speed": speed,
    "distance": distance,
    "asl": asl,
    "time": time,
    "finished": finished,
    "createAt": "${createAt.year.toString().padLeft(4, '0')}-${createAt.month.toString().padLeft(2, '0')}-${createAt.day.toString().padLeft(2, '0')}",
    "fav": fav,
    "points": List<dynamic>.from(points.map((x) => List<dynamic>.from(x.map((x) => x.toJson())))),
    "markers": List<dynamic>.from(markers.map((x) => x.toJson())),
  };
}

class Marker {
  String caption;
  int time;
  double lng;
  double lat;

  Marker({
    required this.caption,
    required this.time,
    required this.lng,
    required this.lat,
  });

  factory Marker.fromJson(Map<String, dynamic> json) => Marker(
    caption: json["caption"],
    time: json["time"],
    lng: json["lng"]?.toDouble(),
    lat: json["lat"]?.toDouble(),
  );

  Map<String, dynamic> toJson() => {
    "caption": caption,
    "time": time,
    "lng": lng,
    "lat": lat,
  };
}

class Point {
  int section;
  int time;
  double lng;
  double lat;
  int asl;
  int distance;

  Point({
    required this.section,
    required this.time,
    required this.lng,
    required this.lat,
    required this.asl,
    required this.distance,
  });

  factory Point.fromJson(Map<String, dynamic> json) => Point(
    section: json["section"],
    time: json["time"],
    lng: json["lng"]?.toDouble(),
    lat: json["lat"]?.toDouble(),
    asl: json["asl"],
    distance: json["distance"],
  );

  Map<String, dynamic> toJson() => {
    "section": section,
    "time": time,
    "lng": lng,
    "lat": lat,
    "asl": asl,
    "distance": distance,
  };
}
